package com.zx.designpattern.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.zx.designpattern.R;
import com.zx.designpattern.view.adapter.GirlAdapter;
import com.zx.designpattern.base.BaseActivity;
import com.zx.designpattern.presenter.GirlsPresenter;
import com.zx.designpattern.view.IBaseView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MVPActivity extends BaseActivity<IBaseView, GirlsPresenter<IBaseView>> {
    @BindView(R.id.listview)
    ListView listview;

    @OnClick(R.id.btn_clear)
    void btnClear(View view) {
        basePresenter.clearData();
    }

    @OnClick(R.id.btn_add)
    void btnAdd(View view) {
        basePresenter.addData();
    }
    GirlAdapter mGirlAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        basePresenter.fetch();
    }


    @Override
    protected int getRootViewId() {
        return R.layout.activity_mvp;
    }

    @Override
    protected GirlsPresenter<IBaseView> createPresenter() {
        return new GirlsPresenter();
    }


    @Override
    public void showView(int code, Object data) {
        switch (code) {
            case 1:
                mGirlAdapter = new GirlAdapter(this, (List) data);
                listview.setAdapter(mGirlAdapter);
                break;
            case 2:
                mGirlAdapter.clearData();
                break;
            case 3:
                mGirlAdapter.addData((List) data);
                break;
        }
    }
}
